import com.jly.mapper.OrderAnnotationMapper;
import com.jly.po.Order;
import com.jly.po.vo.OrderVO;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;


public class testAnnotation {

    private OrderAnnotationMapper orderAnnotationMapper;

    @Before
    public void before() throws IOException {
        InputStream resourceAsStream =
                Resources.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new
                SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession(true);
        orderAnnotationMapper = sqlSession.getMapper(OrderAnnotationMapper.class);
    }

//    @Test
//    public void testAdd() {
//        User user = new User();
//        user.setUsername("测试数据");
//        user.setPassword("123");
//        userMapper.add(user);
//    }
//
//    @Test
//    public void testUpdate() throws IOException {
//        User user = new User();
//        user.setId(5);
//        user.setUsername("测试数据修改");
//        user.setPassword("abc");
//        userMapper.update(user);
//    }
//
//    @Test
//    public void testDelete() throws IOException {
//        userMapper.delete(5);
//    }

//    @Test
//    public void testFindById() throws IOException {
//        User user = userMapper.findById(1);
//        System.out.println(user);
//    }

    @Test
    public void testFindAll() throws IOException {
        List<OrderVO> all = orderAnnotationMapper.findAll();
        for (OrderVO order : all) {
            System.out.println(order);
        }
    }
}
